﻿<UserControl x:Class="TreeBuilder.NodeFrame"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:tb="clr-namespace:TreeBuilder"
             xmlns:ctrl="clr-namespace:Elderos.Controls;assembly=Elderos.Controls"
             xmlns:cp="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
             mc:Ignorable="d" 
             d:DesignHeight="320" d:DesignWidth="300" BorderBrush="Black"
             GotFocus="Rectangle_GotFocus"
             LostFocus="Rectangle_LostFocus"
             Focusable="True"
             Panel.ZIndex="1"
             >
    <UserControl.Resources>
        <ResourceDictionary>
            <SolidColorBrush x:Key="PathBrush" Color="Black"/>
            <Style x:Key="MenuStyle" TargetType="FrameworkElement">
                <Setter Property="Visibility" Value="Hidden"/>
            </Style>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Nodes/NodeResources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <StackPanel Orientation="Vertical">
        <WrapPanel 
            Name="ButtonPanel" 
            Background="{x:Static SystemColors.ControlBrush}"
            ItemWidth="25" 
            ItemHeight="25" 
            Height="25"
            Width="125"
            Panel.ZIndex="2"
            Style="{StaticResource MenuStyle}"
            HorizontalAlignment="Center">
            <Button x:Name="LineButton" Style="{StaticResource ButtonStyle}" Content="{StaticResource LineImage}"
                    Click="LineButton_Click" Focusable="False"
                    />
            <Button x:Name="ArrowButton" Style="{StaticResource ButtonStyle}" Content="{StaticResource ArrowImage}"
                    Click="ArrowButton_Click" Focusable="False"/>
            <tb:DragButton x:Name="DragButton"
                PreviewMouseDown="DragButton_MouseDown"
                           />
            <Button x:Name="TriangleButton" Style="{StaticResource ButtonStyle}" Content="{StaticResource TriangleImage}"
                    Click="TriangleButton_Click" Focusable="False"/>
            <Button x:Name="DeleteButton" 
                    Style="{StaticResource ButtonStyle}"
                    Content="{StaticResource DeleteImage}"
                    Click="DeleteButton_Click" Focusable="False"
                    />
        </WrapPanel>
        <Path Name="MainPath"
                    Focusable="True"
                    SizeChanged="MainPath_SizeChanged"
                    HorizontalAlignment="Center"
                    Loaded="MainPath_OnLoaded"
                    PreviewMouseLeftButtonUp="Rectangle_PreviewMouseUp"
                    PreviewMouseUp="MainPath_PreviewMouseUp"
                    PreviewMouseRightButtonUp="MainPath_PreviewMouseRightButtonUp"
                    PreviewMouseRightButtonDown="MainPath_PreviewMouseRightButtonDown"
                    PreviewMouseDown="MainPath_PreviewMouseDown"
                    MouseUp="HandleEvent"
                    MouseDown="HandleEvent"
              >
            <Path.ContextMenu>
                <ContextMenu Name="Menu" Closed="Menu_Closed" Opened="Menu_Opened">
                    <MenuItem>
                        <MenuItem.Header>
                            <cp:ColorPicker x:Name="ColorPicker" VerticalContentAlignment="Stretch"/>
                        </MenuItem.Header>
                    </MenuItem>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Label Content="Thickness:"/>
                        <ctrl:ValidatableTextBox Style="{StaticResource ValidatableBoxStyle}" 
                                                 Name="ThicknessBox"
                    Grid.Column="1"
                    MinWidth="30"
                    Text=""
                    Validate="ValidateDouble" FinalValidation="ValidateThickness" DefaultValue="1"           
                        />
                    </Grid>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*"/>
                            <ColumnDefinition Width="4*"/>
                        </Grid.ColumnDefinitions>
                        <Label Content="Dashes:"/>
                        <ctrl:ValidatableTextBox Style="{StaticResource ValidatableBoxStyle}" Grid.Column="1"
                        Text="{Binding ElementName=MainPath,Path=StrokeDashArray, Mode=TwoWay}"
                                         Validate="ValidateDoubleCollection" FinalValidation="ParseDoubleCollection" DefaultValue=""
                        MinWidth="30"
                        />
                    </Grid>
                </ContextMenu>
            </Path.ContextMenu>
            <Path.Data>
                <PathGeometry>
                    <PathFigure x:Name="PathFigure" StartPoint="20,0">
                        <LineSegment x:Name="UpperLine" Point="280,0"/>
                        <BezierSegment x:Name="UpperRightBezier" Point1="300,0" Point2="300,0" Point3="300,20"/>
                        <LineSegment x:Name="RightLine" Point="300, 280"/>
                        <BezierSegment x:Name="LowerRightBezier" Point1="300,300" Point2="300,300" Point3="280,300"/>
                        <LineSegment x:Name="BottomLine" Point="20,300"/>
                        <BezierSegment x:Name="LowerLeftBezier" Point1="0,300" Point2="0,300" Point3="0,280"/>
                        <LineSegment x:Name="LeftLine" Point="0, 20"/>
                        <BezierSegment x:Name="UpperLeftBezier" Point1="0,0" Point2="0,0" Point3="20,0"/>
                    </PathFigure>
                </PathGeometry>
            </Path.Data>
        </Path>
    </StackPanel>
</UserControl>
